//
//  SLMessageController.swift
//  Sina15
//
//  Created by 盼 on 16/4/6.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

class SLMessageController: SLBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupMessageInfo()
    }


    private func setupMessageInfo(){
        visitorView?.setupViewInfo(title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", imageName: "visitordiscover_image_message")
        
        if userLogin == true {
           
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "发现群", target: self, action: "push")
        }
        
        tabBarItem.badgeValue = "10"
        
        setBackGround()
    }

    private func setBackGround(){
        
        //遍历tabBar的子视图
        for subview in (tabBarController?.tabBar.subviews)! {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                for sub in subview.subviews {
                    
                    if sub.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        
                        for bgSub in sub.subviews {
                            
                            if bgSub.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                
                                bgSub.setValue(UIImage(named: "main_badge"), forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
    }
    
    @objc private func push(){
        //当badgeValue被赋值为nil之后再重新赋值，背景图片会变回为系统背景图片，所以需要自定义UITabBarItem
        tabBarItem.badgeValue = nil
        tabBarItem.badgeValue = "\(random()%101)"
        print("发现群")
    }

}
